/// Coder: Jose Ricardo Mello Viana - 2008
/// Bugs? e-mail me: zezim.ricardo@gmail.com

/**
 *
 * Author: Jose Ricardo (zezim)
 *
 * Data created: 09-05-08
 *
 **/

#ifndef _PAINT_CURSOR_H_
#define _PAINT_CURSOR_H_

#include "lal/Point3.hpp"
#include "lal/Vector3.hpp"
#include "lal/Color.hpp"
#include "glslKernel/glslKernel.h"

#include <GL/glut.h>
#include <vector>

#define PI 3.1415926535897932384626433832795

using namespace LAL;
using namespace std;

typedef Point3<double> Point;
typedef Point3<int> iPoint;
typedef Vector3<double> Vector;

class PaintCursor {
public:
   /// Default constructor
   PaintCursor();

   /// Constructor
   /// @param x given x screen position
   /// @param y given y screen position
   PaintCursor(GLint x, GLint y);

   /// Default destructor
   virtual ~PaintCursor();

   /// Update world cursor position
   /// @param x given x screen position
   /// @param y given y screen position
   void updatePosition(GLint x, GLint y);

   /// Draw cursor
   void draw();

   /// Update cursor
   void update();

   /// Increase zoom of cursor
   void in();

   /// Decrease zoom of cursor
   void out();

   /// Increase number of points in cursor
   void increase();

   /// Decrease number of points in cursor
   void decrease();

   /// Get cursor normal
   /// @return normal
   Vector getNormal() { return normal; };

   /// Get cursor screen position
   /// @return screen position
   iPoint getScreenPosition() { return sPosition; };

   /// Get cursor color
   /// @return cursor color
   Color getColor(){ return color; };

   /// Set cursor color
   /// @param cursor color
   Color setColor(Color c){ color = c; };

   /// Get cursor points
   /// @return points of cursor
   vector<Point> getCursorPoints() { return points; };

   /// Get cursor points (integer)
   /// @return points of cursor
   vector<iPoint> getCursorPointsi() { return ipoints; };

   /// Represents paint cursor click
   void click() { clicked = true; };

   /// Represents paint cursor unclick
   void unclick() { clicked = false; };

   /// Get state of cursor
   /// @return clicked
   bool isClicked() { return clicked; };

   /// Multiply the matrix m by a point p
   /// @param m given matrix
   /// @param p given point
   /// @return multiplied point
   Point MatrixMult(GLdouble m[16], Point p);

   /// Returns the cursor current format
   /// @return size * number_points
   GLdouble getFormat() { return size * number_points + normal[0] + normal[1] + normal[2]; };

private:
   iPoint sPosition;
   Point position;
   glslKernel *shader_cursor;

   Vector normal;

   GLdouble size;
   GLdouble number_points;
   vector<Point> points;
   vector<iPoint> ipoints;

   Color color;

   bool clicked;
};

#endif /*_PAINT_CURSOR_H_*/
